﻿using Common.ECS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

public class CollisionAdapter :MonoBehaviour, IAdapter
{
    List<ICollisionComponent> CollisionComponents = new List<ICollisionComponent>();

    public string GetPathInParent()
    {
        return gameObject.name;
    }

    public void RegisterComponent(IComponent component)
    {
        CollisionComponents.Add((ICollisionComponent)component);
    }

    private void OnCollisionEnter(Collision collision)
    {
        for (int i = 0; i < CollisionComponents.Count; i++)
        {
            if (CollisionComponents[i] != null)
            {
                if (collision.collider.tag == CollisionComponents[i].TargetTag)
                {
                    CollisionComponents[i].EnterObjs.Add(collision.gameObject);
                }
            }
        }


    }

    private void OnCollisionExit(Collision collision)
    {
        for (int i = 0; i < CollisionComponents.Count; i++)
        {
            if (CollisionComponents[i] != null)
            {
                if (collision.collider.tag == CollisionComponents[i].TargetTag)
                {
                    CollisionComponents[i].EnterObjs.Remove(collision.gameObject);
                }
            }
        }
    }
}